package cn.fws.meap.community.web;

import java.util.List;

import cn.fws.meap.system.constants.QiNiuParam;
import cn.fws.meap.utils.QiNiuUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import cn.fws.meap.community.entity.Resources;
import cn.fws.meap.community.service.IResourcesService;
import cn.fws.framework.web.contoller.BaseController;
import cn.fws.framework.web.page.PagingResult;
import cn.fws.framework.web.contoller.JsonResponse;

import javax.servlet.http.HttpServletRequest;

/**
 * 资源 信息操作处理
 * 
 * @author chenkh
 * @date 2019-03-07
 */
@RestController
@RequestMapping("/meap/resources")
@Api(tags = "资源 信息操作处理")
public class ResourcesController extends BaseController{

	@Autowired
	private IResourcesService resourcesService;
	
	/**
	 * 查询资源列表
	 */
	//@RequiresPermissions("meap:resources:list")
	@ApiOperation(value = "查询资源列表")
	@ApiImplicitParams(@ApiImplicitParam(value = "不用传参"))
	@PostMapping("/list")
	public PagingResult<Resources> list(Resources resources){
		startPage();
        List<Resources> list = resourcesService.selectList(resources);
		return getPagingResult(list);
	}
	
	/**
	 * 新增保存资源
	 */
	//@RequiresPermissions("meap:resources:add")
	@ApiOperation(value = "新增保存资源")
	@ApiImplicitParams(
			@ApiImplicitParam(name = "resources", value = "新增保存资源",dataType = "Resources"))

	@PostMapping("/add")

	public int addSave(Resources resources)	{


		return resourcesService.insert(resources);
	}

	/**
	 * 修改保存资源
	 */
	// @RequiresPermissions("meap:resources:edit")
	@ApiOperation(value = "修改保存资源")
	@ApiImplicitParams(
			@ApiImplicitParam(name = "resources", value = "修改保存资源",dataType = "Resources"))
	@PutMapping("/edit")
	public JsonResponse editSave(Resources resources)	{		
		return toAjax(resourcesService.update(resources));
	}
	
	/**
	 * 删除资源
	 */
	//@RequiresPermissions("meap:resources:remove")
	@ApiOperation(value = "删除资源")
	@ApiImplicitParams(
			@ApiImplicitParam(name = "ids", value = "根据id删除资源",dataType = "String"))
	@DeleteMapping( "/remove")
	public JsonResponse remove(String ids)	{		
		return toAjax(resourcesService.deleteByIds(ids));
	}
	
	/**
	 * 获取七牛token
	 */
	//@RequiresPermissions("meap:resources:remove")
	@ApiOperation(value = "获取七牛图像token")
	@PostMapping( "/getImgUploadToken")
	public String getImgUploadToken()	{		
		return QiNiuUtil.getUploadToken(QiNiuParam.MEAP_IMG);
	}
	
}
